import { join } from 'path';
import { IMessage } from 'qq-guild-bot';
import { readYaml } from '../../../src/lib/tool';

export async function bqlist(e: { eventType: string; msg: IMessage }) {
  // 私聊禁用
  if (e.eventType === 'DIRECT_MESSAGE_CREATE') {
    return;
  }

  let bqPath = join(process.cwd(), '/plugins/biaoqing/resources/biaoqing/biaoqing.yaml');

  let bq = readYaml(bqPath);
  if ((bq ?? '') === '' || typeof bq === 'string' || Object.keys(bq).length === 0) {
    let message = {
      content: `<@!${e.msg.author.id}> 暂时没有表情!`,
      msg_id: e.msg.id
    };
    await client.messageApi.postMessage(e.msg.channel_id, message);
  } else {
    let list = Object.keys(bq);

    let msg = '';
    let i = 1;
    for (let item of list) {
      msg += i + '、' + item + '\n';
      i++;
    }
    let message = {
      content: msg,
      msg_id: e.msg.id
    };
    await client.messageApi.postMessage(e.msg.channel_id, message);
  }

  return true;
}
